#include "camprec.h"
#include "MyStatusBar.h"


CMyStatusBar::CMyStatusBar(wxWindow *parent): wxStatusBar(parent, wxID_ANY), m_timer(this),m_pProgressBar(0)
{
	static const int widths[Field_Max] = { -1, -1, -1, 150,70 };
	SetFieldsCount(Field_Max);
    SetStatusWidths(Field_Max, widths);

	UpdateClock ();


	m_timer.Start(1000);

	Connect (wxEVT_SIZE, wxSizeEventHandler(CMyStatusBar::OnSize));
	Connect (wxEVT_TIMER, wxTimerEventHandler (CMyStatusBar::OnTimer));

	
	
	m_pProgressBar = new wxGauge (this, 1000,100);
	SetProgressValue (0);

	
	MoveProgress ();

}


CMyStatusBar::~CMyStatusBar(void)
{
	if ( m_timer.IsRunning() )
    {
        m_timer.Stop();
    }

	//if (m_pProgressBar)
	//	delete m_pProgressBar;
}


void CMyStatusBar::OnSize(wxSizeEvent& event)
{
	wxSize size = event.GetSize ();
	wxString s; 
	s = s.Format (wxT("size %d, %d"), size.x, size.y);
	SetStatusText (s, Field_Text);


	MoveProgress ();


}

void CMyStatusBar::OnTimer (wxTimerEvent &event)
{
	UpdateClock ();

	//if (m_pProgressBar->GetValue() <=90)
	//	SetProgressValue (m_pProgressBar->GetValue() + 10);
	//else
	//	SetProgressValue (0);
	//m_pProgressBar->SetValue (m_pProgressBar->GetValue() + 10);
}

void CMyStatusBar::MoveProgress (/*const wxRect &rect*/)
{
	wxRect rect;
	GetFieldRect(Field_Progress, rect);
	
	m_pProgressBar->SetSize (rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);
}

void CMyStatusBar::UpdateClock ()
{
	SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock);
}

void CMyStatusBar::SetProgressValue (const int &val, const wchar_t *message)
{
	if ((val == 0)||(val == 100))
	{
		m_pProgressBar->Show (false);
		SetStatusText(L"", Field_Message);

	}
	else
	{
		m_pProgressBar->Show ();
		m_pProgressBar->SetValue (val);

		SetStatusText(message, Field_Message);
	}
}